package org.springboot.base.user.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.springboot.base.user.does.UserDO;
import org.springboot.base.user.mapper.UserMapper;
import org.springboot.base.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @author ZJL
 * @DateTime 2019年2月6日 上午12:08:17
 * 
 **/
@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public UserDO getUser(Long userId) {
		// TODO Auto-generated method stub
		System.out.println("getUser");
		UserDO user = new UserDO();
		user.setUserId(100000L);
		user.setUserName("userName10000");
		user.setUserPwd("userPwd10000");
		user.setUserAge(20);
		user.setUserBirthday(Calendar.getInstance().getTime());
		user = this.userMapper.getUser(userId);
		return user;
	}

	@Override
	public List<UserDO> listUser(String userName) {
		// TODO Auto-generated method stub
		System.out.println("listUser");
		List<UserDO> list = new ArrayList<UserDO>();
		UserDO user = null;
		for(int i=0;i<10;i++) {
			user = new UserDO();
			user.setUserId(100000L+i);
			user.setUserName("userName10000"+i);
			user.setUserPwd("userPwd10000"+i);
			user.setUserAge(20+i);
			user.setUserBirthday(Calendar.getInstance().getTime());
			list.add(user);
		}
		//查询数据库
		list = this.userMapper.listUser(user);
		return list;
	}

	@Override
	public UserDO addUser(UserDO user) {
		// TODO Auto-generated method stub
		System.out.println("addUser");
		user = new UserDO();
		user.setUserId(100000L);
		user.setUserName("userName10000");
		user.setUserPwd("userPwd10000");
		user.setUserAge(20);
		user.setUserBirthday(Calendar.getInstance().getTime());
		return user;
	}

	@Override
	public UserDO updateUser(UserDO user) {
		// TODO Auto-generated method stub
		System.out.println("updateUser");
		user = new UserDO();
		user.setUserId(100000L);
		user.setUserName("userName10000");
		user.setUserPwd("userPwd10000");
		user.setUserAge(20);
		user.setUserBirthday(Calendar.getInstance().getTime());
		return user;
	}

	@Override
	public int deleteUser(Long userId) {
		// TODO Auto-generated method stub
		System.out.println("deleteUser");
		return 1;
	}

	@Override
	public List<UserDO> listUser() {
		System.out.println("list");
		List<UserDO> list = new ArrayList<UserDO>();
		UserDO user = null;
		for(int i=0;i<10;i++) {
			user = new UserDO();
			user.setUserId(100000L+i);
			user.setUserName("userName10000"+i);
			user.setUserPwd("userPwd10000"+i);
			user.setUserAge(20+i);
			user.setUserBirthday(Calendar.getInstance().getTime());
			list.add(user);
		}
		//分页插件查询
		PageHelper.startPage(1,3).setOrderBy("user_id desc");
		list = this.userMapper.listUser(user);
		final PageInfo<UserDO> pageInfo = new PageInfo<UserDO>(list);
		System.out.println("list.size=="+list.size());
		//查询数据库
		//list = this.userMapper.listUser(user);
		list = pageInfo.getList();
		return list;
	}

}
